<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
<%	pageContext.setAttribute("ctx", request.getContextPath());	%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>File Manager</title>
<link rel="stylesheet" type="text/css" href="${ctx}/css/default.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/js/jqueryeasyui12/themes/bootstrap/easyui.css" />
<link href="${ctx}/js/uploadify3.2/uploadify.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="${ctx}/js/jqueryeasyui12/themes/icon.css" />
<script type="text/javascript" src="${ctx}/js/jqueryeasyui12/jquery.min.js"></script>
<script type="text/javascript" src="${ctx}/js/jqueryeasyui12/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/js/ipebg/IPEBG.js"></script>
<script type="text/javascript" src="${ctx}/js/ipebg/COMMON.js"></script>
<script type="text/javascript" src="${ctx}/js/jqueryeasyui12/locale/easyui-lang-zh_TW.js"></script>
<script type="text/javascript" src="${ctx}/js/ipebg/easyui_ext.js"></script>
<script type="text/javascript" src="${ctx}/js/ipebg/UploadFile.js"></script>
<script type="text/javascript" src="${ctx}/js/uploadify3.2/jquery.uploadify.js"></script>

<script>
var ctx = '${ctx}';
var MutiFileUpload={};
var filePrefixUrl='${filePrefixUrl}'
var param1={'':''};
var optionType='';
$(function(){
	function formatter (value){
		  if(!value)return "";
        return new Date((value - 0)).format("yyyy-MM-dd");
    }
	
	$("table[id=tableShow]").show();
	$('#fileTable').datagrid({
		title:'File list:',
		nowrap: false,
		striped: true, 
		scrollbarSize:0,
		fitColumns: true, 
		url: ctx + '/fastdfs.do?action=fileListQuery',
		remoteSort: false,
		singleSelect:false,
		rownumbers:true,
		frozenColumns:[[
		    {field:'ck',checkbox:true,width:30} 
		]],
		columns:[[
			{field:'fileId',title:'ID',width:50,hidden: true},
			{field:'fileRealName',title:'fileRealName',width:150,
				formatter:function(value,rowdata){
	                var path=filePrefixUrl+rowdata.fileStorageGroup+"/"+rowdata.fileRemoteName;
	                return '<a href="javascript:void(0);" onclick="window.open(\''+path+'\')">'+value+'</a>';
	               // return '<img src="'+path+'"/>';
	            }
			},
			{field:'fileRemoteName',title:'fileRemoteName',width:200},
			{field:'fileStorageGroup',title:'fileStorageGroup人',width:80},
			{field:'fileType',title:'fileType',width:60},
			{field:'uploadDatetime',title:'uploadDatetime',width:50,formatter:formatter},
			{field:'enabled',title:'enabled',width:50}
		]],
		queryParams:param1,
		pagination:true,
		pageSize:100,
		pageList:[100,500,1000]
	}), 
	$("#queryBtn").on("click", function (){  //查找
		var fileRealName = $("#fileRealName").textbox("getValue").trim();
		var param2 = {
				"fileRealName":fileRealName
			};
			$('#fileTable').datagrid('load', param2);
	})		
});

MutiFileUpload.initImportFormWin=function(){
	 $('#txtUploadResult').val('');
	UploadFile('fileupload',ctx,{
		uploader:ctx+'/fastdfs.do?action=uploadFile',
		buttonText : "File Select",
		queueId:"fileQueue",
		fileSizeLimit:"100MB",
		fileTypeDesc : '*.*;', // 如果配置了以下的'fileExt'属性，那么这个属性是必须的
        fileTypeExts : '*.*',// 允许的格式
		onUploadSuccess : function(fileObj, data, response) {
			//alert(data);
			//$('#txtUploadResult').val(data);
			data = IPEBG.str2json(data);
			 if (data.success) {
				 $('#fileTable').datagrid('load', '');
				 //alert(data.path);
			 }
		},onUploadError : function(file, errorCode, errorMsg, errorString) {
			alert("onError:" + fileObj.name);
		},onSelectError:function(file, errorCode, errorMsg){
            debugger;
            switch (errorCode) {
                case -110:
                    alert("文件不能大於100M！");
                    break;
                case -130:
                    alert("Please change file type!");
                    break;
            }
            return false;
        }
	}); 
}

MutiFileUpload.openImportFormWin=function(){
	optionType='IMPORT_FILE';
	var importWin = $("#importWin").window({
		left:100,
		top:50
	});
	importWin.slideDown();//显示 
	$("#importFileForm").form("clear");
	$("#fileQueue").empty();
	importWin.find("input").val("");
	importWin.window('open');
	MutiFileUpload.initImportFormWin();

}


MutiFileUpload.deleteRow=function() {
	var selected = $('#fileTable').datagrid('getSelected');
	var selections = $('#fileTable').datagrid('getSelections');
	var allFilesInfo = "",strFileInfo="";
		
	if (selected) {
		$.each(selections,function(i){
			 strFileInfo =  selections[i].fileId+':'+selections[i].fileStorageGroup+':'+selections[i].fileRemoteName;			 
			 allFilesInfo=allFilesInfo+strFileInfo+";";
		});
		alert(allFilesInfo);
		$.messager.confirm('系統提示', '您確定要刪除該記錄嗎?', function(r) {
			if (r) {
				$.ajax({
					type : "POST",
					url : ctx + '/fastdfs.do?action=delFiles',
					data : {
						"allFilesInfo" : allFilesInfo
					},
					dataType : "text",
					cache : false,
					error : function(textStatus, errorThrown) {
						$.messager.alert('系統提示', '系統錯誤(' + textStatus
								+ '): ' + errorThrown, 'error');
					},
					success : function(data, textStatus) {
						if (data == 'SUCCESS') {
							$.messager.alert('系統提示', '刪除成功！', 'info');
							$('#fileTable').datagrid('reload');
						} else {
							$.messager.alert('系統提示', '刪除失敗！', 'info');
						}
					}
				});
			}
		});
	} else {
		$.messager.alert('系統提示', '請先選擇一筆資料再進行刪除!', 'info');
	}
}


MutiFileUpload.cancel=function(){
	//alert('a');
	$('#fileTable').datagrid('load', param1);
  	$("#importWin").window('close');
  	
}

</script>
</head>
<body>
<div style="width: 99%">
		<table id="fileTable" toolbar="#tb"></table>
		<div id="tb">
				<table width="100%" id="tableShow" style="display: none;">
					<tr>
						<td width="60%" style="white-space: nowrap;">
						<a href="#" id="btnimport" class="easyui-linkbutton" iconCls="icon-undo" plain="true" code="IMPORT" onclick="MutiFileUpload.openImportFormWin()">Import File</a>
						<a href="#" id="btncut" class="easyui-linkbutton" iconCls="icon-remove" plain="true"  code="DELETE" onclick="MutiFileUpload.deleteRow()">刪除</a>
						
						<td width="40%" style="white-space: nowrap; padding: 0px" align="right">
							<span style="font-family: SimSun; font-size: 13px">File Name:</span> 
							<input type="text" id="fileRealName" class="easyui-textbox" style="width:100px;height:20px;"/>
							<a class="easyui-linkbutton" iconCls="icon-search" plain="true" href="#" code="QUERY" onclick="query()">查詢</a>
               			</td>
					</tr>
				</table>
		</div>
	</div>
	
	<div id="importWin" class="easyui-window" title="批量導入文件" style="width:800px;height:400px;display: none;"
		 collapsible="false" maximizable="false" minimizable="false" resizable="true" modal="true" closed="true"
		 data-options="iconCls:'icon-save',footer:'#footer'">
		<form id="importFileForm" name="signLineImportForm" method="post" class="fm">
			<input type="hidden" id='hidImportFileName'>
			<div id="fillImportContent" style="float: left;"><br>
				<table class="formTbl" style="font-size: 13px">
					<tr style="height:30px;">
						<td>說明:</td>
						<td>首次使用，如果沒有看到<font style="color: red" >文件選擇</font>	按鈕
							<a  href="http://ipebg110.efoxconn.com/potres/baseImg/install_flash_player_ax.exe" ><font style="color: blue;" >請點擊這裡下載Adobe flash插件</font></a>							
						</td>
					</tr>					
					<tr style="height:30px;">
						<td>文件選擇:</td>
						<td><input id="fileupload" name="fileupload" type="file" /><div id="fileQueue" ></td>
					</tr>
				</table>
				</div>				
			</div>
		</form>
	</div>	
	<div id="footer" align="center" style="padding: 5px;">
		<!-- <a href="#" id="saveBtn" class="easyui-linkbutton"  data-options="iconCls:'icon-ok'"  onclick="MutiFileUpload.save()">保存</a> --> 
		<a href="#" id="cancel" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="MutiFileUpload.cancel()">關閉</a>
	</div>
</body>
</html>